import 'dart:async';
import 'dart:io';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:get/get.dart';
import 'package:hixing_app/router/home/home_router.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:hixing_app/const/gaps.dart';

import 'package:hixing_app/extensions/str_ext.dart';

import 'package:hixing_app/utils/export_utils.dart';
import 'package:hixing_app/utils/open_screen_utils.dart';
import 'package:hixing_app/utils/storage/storage.dart';
import 'package:hixing_app/utils/utils.dart';

class SplashPage extends StatefulWidget {
  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  int count = 3;

  // File? file;

  Future<void> startTime() async {
    if (count <= 0) {
      print("倒计时结束");
      Get.offAndToNamed(HomeRouter.mainPage);
    } else {
      await Future.delayed(Duration(seconds: 1));
      setState(() {
        count = count - 1;
      });
      startTime();
    }
  }

  @override
  void initState() {
    startTime();
    // 第一次安装需要判断网络是否确认
    // starTime();
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Container(
          alignment: Alignment.center,
          color: Colors.orange,
          child: Text(
            "启动图",
            style:
                TextStyle(decoration: TextDecoration.none, color: Colors.black),
          ),
        ),
        Positioned(
            bottom: 40,
            right: 20,
            child: GestureDetector(
              onTap: () {
                count = 0;
                Get.offAndToNamed(HomeRouter.mainPage);
              },
              child: DefaultTextStyle(
                style: TextStyle(color: Colors.white, fontSize: 14),
                child: Container(
                  width: 60,
                  height: 30,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(20),
                    color: Colors.grey.withOpacity(0.5),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [Text('$count'), const Text('跳过')],
                  ),
                ),
              ),
            ))
      ],
    );

    //   Scaffold(
    //   appBar: AppBar(
    //     title: Text('广告页'),
    //   ),
    //   body: Center(
    //       child: Column(
    //     mainAxisAlignment: MainAxisAlignment.center,
    //     children: [
    //       Text('$_count'),
    //       ElevatedButton(onPressed: onEnd, child: const Text('跳过'))
    //     ],
    //   )),
    // );
  }
}
